package com.lc.luzhengtang.conn;

import android.util.Log;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/4/17.
 */
@HttpInlet(Conn.GENERAL_ORDER)
public class ConngenerateOrder extends BaseAsyPost<ConngenerateOrder.Info> {

    public String member_id, cart_id;


    public ConngenerateOrder(String member_id, String cart_id, AsyCallBack<ConngenerateOrder.Info> asyCallBack) {
        super(asyCallBack);

        this.member_id = member_id;
        this.cart_id = cart_id;

    }

    @Override
    protected ConngenerateOrder.Info parser(JSONObject object) throws Exception {
        Log.d(object.toString(), "aaaaaaaaaaaaaaaaa");
        Log.d(object.toString(), "aaaaaaaaaaaaaaaaa");
        ConngenerateOrder.Info info = null;
        if (object.optInt("code") == 200) {
            info = new ConngenerateOrder.Info();
            info.code = object.optInt("code");
            info.message = object.optString("message");
            JSONObject object_commen = object.optJSONObject("data");
            JSONArray array = object_commen.optJSONArray("goods");
            List<ConngenerateOrder.Info.Goods> bannerList = new ArrayList();
            for (int i = 0; i < array.length(); i++) {
                JSONObject object1 = array.optJSONObject(i);
                ConngenerateOrder.Info.Goods listContent = new ConngenerateOrder.Info.Goods();
                listContent.member_id = object1.optString("member_id");
                listContent.number = object1.optString("number");
                listContent.goods_id = object1.optString("goods_id");
                listContent.goodsattr = object1.optString("goodsattr");
                listContent.title = object1.optString("title");
                listContent.picurl = object1.optString("picurl");
                listContent.market_price = object1.optString("market_price");
                listContent.weight = object1.optString("weight");
                listContent.postage = object1.optInt("postage");
                listContent.sales = object1.optString("sales");
                bannerList.add(listContent);
            }
            info.goods = bannerList;
            JSONArray array1 = object_commen.optJSONArray("address");
            List<ConngenerateOrder.Info.Address> menuList = new ArrayList();
            for (int i = 0; i < array1.length(); i++) {
                JSONObject object1 = array1.optJSONObject(i);
                ConngenerateOrder.Info.Address listContent = new ConngenerateOrder.Info.Address();

                listContent.id = object1.optInt("id");
                listContent.member_id = object1.optInt("member_id");
                listContent.address = object1.optString("address");
                listContent.username = object1.optString("username");
                listContent.mobile = object1.optString("mobile");
                listContent.city = object1.optString("city");
                listContent.status = object1.optInt("status");
                listContent.postage = object1.optString("postage");
                listContent.zongintegralmoney = object1.optString("zongintegralmoney");
                listContent.zongintegral = object1.optInt("zongintegral");

                listContent.ordersn = object1.optString("ordersn");
                listContent.balance = object1.optString("balance");
                listContent.zonggoodsmoney = object1.optString("zonggoodsmoney");

                menuList.add(listContent);
            }
            info.address = menuList;

            return info;
        } else if (object.optInt("code") == 400) {

            info = new ConngenerateOrder.Info();
            info.code = object.optInt("code");
            info.message = object.optString("message");
            return info;
        } else {

        }

        return null;


    }


    public static class Info {


        public String message;

        public List<Goods> goods;
        public List<Address> address;
        public int code;
        public static class Goods {
            public String id;
            public String member_id;
            public String number;
            public String goods_id;
            public String goodsattr;
            public String title;
            public String picurl;
            public String market_price;
            public String weight;
            public int postage;
            public String sales;

        }


        public static class Address {
            public int id;
            public int member_id;
            public String address;
            public String username;

            public String mobile;
            public String city;
            public int status;
            public String ordersn;
            public String create_time;
            public String postage;
            public String zongintegralmoney;
            public int zongintegral;
            public String balance;
            public String   zonggoodsmoney;

        }


    }

}



